function [c1m,c2m] = conditional_2nd_moment_cum_inflation_sw(mu,r,q,W,HZN)

% [c1m,c2m] = conditional_2nd_moment_cum_inflation_sw(mu,r,q,W,HZN)

% c1m = h-step ahead first moment for cumulative inflation, SW UC model
% c2m = h-step ahead second moment for cumulative inflation, SW UC model
% mu is the random-walk component at date t
% r,q are date-t values for the stochastic volatilities of the measurement
% and state innovations, respectively
% W is the covariance matrix for log-volatility innovations
% HZN is the longest forecast horizon.
% c2m returns a HZNx1 vector of conditional second moments

var_r = W(1,1);
var_q = W(2,2);
h = 1:1:HZN;
rr = r*exp(h'*var_r/2);
rsum = cumsum(rr);
qq = zeros(HZN,1);
for kk = 1:HZN,
    qq(kk) = q*((HZN-kk+1)^2)*exp(kk*var_q/2);
end
qsum = cumsum(qq);
c1m = mu*h';
c2m =  (mu*h').^2 + rsum + qsum;
end

